using System;
using System.Data;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TanashCMS.Business;

/// <summary>
/// Summary description for CMSMasterPageBase
/// </summary>
public class CMSMasterPageBase : System.Web.UI.MasterPage
{
    private string mSystemFeedback = "";
    public virtual string SystemFeedback { get { return mSystemFeedback; } set { mSystemFeedback = value; } }
    public virtual void setPublishLinkVisibility(bool Visible) { }

    protected void BindNavigationMenu(Menu NavigationMenu, TanashWebsite Website)
    {
        NavigationMenu.Items.Clear();
        List<Navigation> navItems = (List<Navigation>)Configuration.GetCurrentSession().CreateQuery("select nav from Navigation nav where nav.Website.ID = " + Website.ID.ToString() + " and nav.ParentID = 0 order by nav.ID").List<Navigation>();
        foreach (Navigation nav in navItems)
        {
            MenuItem menuItem = new MenuItem();
            TreeNode node = new TreeNode();
            menuItem.Text = nav.Title;
            menuItem.Value = nav.ID.ToString();
            if (nav.NavigateURL != "" || nav.TargetID != 0)
                menuItem.NavigateUrl = nav.NavigateURL;
            BindMenuChildren(menuItem, Website);

            NavigationMenu.Items.Add(menuItem);
        }
    }

    private void BindMenuChildren(MenuItem ParentItem, TanashWebsite Website)
    {
        List<Navigation> navItems = (List<Navigation>)Configuration.GetCurrentSession().CreateQuery("select nav from Navigation nav where nav.ParentID = " + ParentItem.Value + " and nav.Website.ID = " + Website.ID.ToString() + " order by nav.ID").List<Navigation>();
        foreach (Navigation nav in navItems)
        {
            MenuItem menuItem = new MenuItem();
            TreeNode node = new TreeNode();
            menuItem.Text = nav.Title;
            menuItem.Value = nav.ID.ToString();
            menuItem.NavigateUrl = nav.NavigateURL;
            BindMenuChildren(menuItem, Website);
            ParentItem.ChildItems.Add(menuItem);
        }
    }

    public new CMSPageBase Page { get { return base.Page as CMSPageBase; } }

}
